<!DOCTYPE html>
<meta charset="utf-8" />
<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
<form action="mpbase/msgCodeManage/queryList.do" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
						<div class="search_elms">
							<div class="search_elm" style="margin-left: 0px;width: 252px;">
								<label class="label_search">错误消息编号:</label>
								<div class="search_input">
									<input id="search_msgId" type="text" name="msgId"
										placeholder="请输入错误消息编号">
								</div>
							</div>
							<div class="search_elm" style="margin-left: 0px;width: 252px;">
								<label class="label_search">错误消息内容:</label>
								<div class="search_input">
									<input id="search_msgContent" type="text" name="msgContent"
										placeholder="请输入错误消息内容">
								</div>
							</div>
							<div class="search_button">
								<button class="btn btn-small btn_search" type="submit" title="搜索">
									搜索
								</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</form>
</div>
	<div class="row">
		<div class="col-xs-12">
			<table id="grid-table"></table>
			<div id="grid-pager"></div>
			
			<div style="margin-top: 10px">
				<span id="auth_btn">
					<a class="btn btn-small btn-add" onclick="addMsgCode();">新增</a>
					<a  class="btn btn-small btn-update" onclick="editMsgCode();">修改</a>
					<a  class="btn btn-small btn-add" onclick="modifyMsgCode();">标记切换</a>
				</span> <span id="paging_bar" style="float: right"> </span>
			</div>
			<!-- PAGE CONTENT ENDS -->
		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<!-- page specific plugin scripts -->
	<script type="text/javascript">
		var jqGrid;
		jQuery(function($) {
			var grid_selector = "#grid-table";
			var pager_selector = "#grid-pager";

			$(window).on(
					'resize.jqGrid',
					function() {
						$(grid_selector).jqGrid('setGridWidth',
								$(".page-content").width());
					})
			var parent_column = $(grid_selector).closest('[class*="col-"]');
			$(document).on(
					'settings.ace.jqGrid',
					function(ev, event_name, collapsed) {
						if (event_name === 'sidebar_collapsed'
								|| event_name === 'main_container_fixed') {
							setTimeout(function() {
								$(grid_selector).jqGrid('setGridWidth',
										parent_column.width());
							}, 0);
						}
					})
			jQuery(grid_selector).jqGrid({

				url : "mpbase/msgCodeManage/queryList.do",
				datatype : "json",
				height : '100%',
				width : '100%',
				colNames : [ 
				              	'错误消息编码',
								'错误消息内容',
								'错误消息标记'
				           ],
				colModel : [ 
							     {name : 'msgId',        index : 'msgId',        width : '100px' , }, 
							     {name : 'msgContent',        index : 'msgContent',        width : '200px' },
							     {name : 'msgFlag',        index : 'msgFlag',        width : '100px' , ditcKey:'MSG_CODE', formatter : gridFormatByDict}
				            ],
				viewrecords : true,
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				altRows : true,
				multiselect : true,//设置行可多选的 
				multiboxonly : true,//
				loadComplete : function() {
					var table = this;
					setTimeout(function() {
						//加载分页
						initPagingBar(grid_selector);
					}, 0);
				},
				beforeRequest : function() {//请求之前执行
					jqGrid = this;
				},
			});
			$(window).triggerHandler('resize.jqGrid');

			$(document).one('ajaxloadstart.page', function(e) {
				$(grid_selector).jqGrid('GridUnload');
				$('.ui-jqdialog').remove();
			});
		});
		
	    //新增
		function addMsgCode() {
			openDialog({
				dialogId : 'dlg-msgCodeAdd',
				title : '新增错误消息',
				pageUrl : 'mpbase/msgCodeManage/addView.do',
				width : '50%',
			    height:'70%'
			});
		}
		
		//修改
		function editMsgCode() {
			var rows = $('#grid-table').jqGrid("getGridParam","selarrrow");
			
			if(rows.length == 0){
				msg.alert("警告","当前没有选择数据项！","error");
				return;
			}
			if(rows.length>1){
				msg.alert("警告","不能同时选择多项数据","warn");
				return;
			}
			var msgId=$('#grid-table').jqGrid('getRowData',rows[0]).msgId;
			openDialog({
				dialogId: 'dlg-custLevelEdit',
				title: '修改错误消息',
				pageUrl: 'mpbase/msgCodeManage/editView.do',
				dataUrl: 'mpbase/msgCodeManage/queryMsgCodeById.do',
				width :'600px',
				height:'400px',
				dataParam: {
					msgId : msgId
				},
				dataName: 'obj' //表单数据存储对象名称
			});
		}
		
		
		//标记切换
	    function modifyMsgCode(){
	            var rows = $('#grid-table').jqGrid("getGridParam","selarrrow");
				
				if(rows.length == 0){
					msg.alert("警告","当前没有选择数据项！","error");
					return;
				}
				if(rows.length>1){
					msg.alert("警告","不能同时选择多项数据","warn");
					return;
				}
				var msgId=$('#grid-table').jqGrid('getRowData',rows[0]).msgId;
				var msgFlag=$('#grid-table').jqGrid('getRowData',rows[0]).msgFlag;
				msgFlag = DICT.getKey('MSG_CODE',msgFlag);
				msg.confirm({title:'确认',position:'center',msg:'您确定要切换选中的错误消息的标记吗？',call:function(ok){
					if(ok){
						$.ajax({
							type : "post",
						    url : "mpbase/msgCodeManage/modifyFlag.do?msgFlag="+msgFlag+"&msgId="+msgId,
							dataType : 'json',
							success : function(result) {
								if (result.rspcod != 200) {
									msg.alert("错误", result.rspmsg + " 错误代码："
											+ result.rspcod, 'error');
								} else {
									msg.alert("提示", result.rspmsg, 'correct');
									$("#grid-table").trigger("reloadGrid");
								}
							},
							error : function(XMLHttpRequest, textStatus) {
								msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
										+ textStatus, 'error');
							}
						});

					}
				}});
				
			}
	</script>